package cookieUtils

import (
	"bookStore/customError"
	"strings"
	"time"
)

var (
	delimiter = "_"
)

func GenerateCookie(key string) string {
	now := time.Now().Format("2006-01-02 15:04:05")
	return now + delimiter + key
}

func ResolveCookie(cookie string) (string, string, error) {
	strSlice := strings.Split(cookie, delimiter)
	if strSlice == nil || len(strSlice) != 2 {
		err := customError.Error{ErrMsg: "cookie信息错误"}
		return "", "", &err
	} else {
		cookieTime := strSlice[0]
		key := strSlice[1]
		return cookieTime, key, nil
	}
}
